package liangtWorkSpace.Observer.swingOfObserver;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @ClassName SwingMain
 * @Description : Swing关于观察者模式的实现
 * @Author : LiangT
 * @Date : 2020/6/19 11:37
 */
public class SwingMain {
    JFrame jFrame;

    public static void main(String[] args) {
        SwingMain swingMain =new SwingMain();
        swingMain.go();
    }
    public void  go(){
        jFrame = new JFrame();
        JButton button = new JButton("这是一个按钮");
        button.addActionListener(new AngelListener());
        button.addActionListener(new DevilListener());
        jFrame.getContentPane().add(BorderLayout.CENTER,button);
    }
    class AngelListener implements ActionListener{

        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("Don't do it, you might regret it!");
        }
    }
    class DevilListener implements ActionListener{
        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("Come on, do it!");
        }
    }
}
